def fibonacci(n): # 生成器函数 - 斐波那契
    a, b, counter = 0, 1, 0
    while True:
        if (counter > n):
            return
        yield a
        a, b = b, a + b
        counter += 1


def fibonacci1(n):
    a,b = 0,1
    for i in range(n):
        yield a
        a,b = b,a+b
    return a


if __name__ == "__main__":
    # 测试while循环
    n = 100
    sum = 0
    counter = 1
    while counter<=n:
        sum+=counter
        counter+=1
    # 最后打印结果
    print("结果为：",sum)
    # for循环练习
    languages  = ["lett","niu","bing"]
    for element in languages:
        print(element,end=",")
    # 使用break语句
    for element in languages:
        if element == "bing":
            print("bing")
        else:
            print(f"element的元素内容为{element}")
    # 使用range进行for循环的处理
    for i in range(5):
        print(i,end=",")
    # 第二种使用range的循环方式
    for i in range(5,9):
        print(f"range第二种表达形式对应的值为{i}")
    # for结合len的循环
    for i in range(len(languages)):
        print(i,languages[i])
    # 测试迭代器
    list = [1, 2, 3, 4]
    for element in list:
        print(element)
    it = iter(list)
    print(next(it))
    print(next(it))
    print(next(it))
    print(next(it))
    print(next(it))
    print("------------------------")
    for element in it:
        print(element)
    # python中迭代器无法通过下标进行访问
    fibonacci(10)
    it = fibonacci1(10)
    for value in it:
        print(value)
    print("fib1的结果为",fibonacci1(10))




